home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
picklst.exe
/
OBJECTS1.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-07-26
|
3KB
|
142 lines
unit Objects1;
{Provides an error function for stream use.
Provides tStrObj, a string object with init, done, load and store
methods for use with collections.
}
{********************************}
{***Programmed by ***}
{***Blake Watson ***}
{***CIS number 70303,373 ***}
{********************************}
interface
uses Objects;
type
pStrObj = ^TStrObj;
tstrobj = object(tObject)
p: pString;
constructor Init(S: String);
constructor Load(S: tStream);
function GetString: String;
procedure Store(S: tStream);
destructor Done; virtual;
end;
pStrObjCollection = ^TStrObjCollection;
tStrObjCollection = object(TCollection)
function StringAt(I: Integer): string;
end;
pStrCollection = ^TStrCollection;
tStrCollection = object(TStringCollection)
function Compare(Key1, Key2: Pointer): Integer; virtual;
end;
PNOCollection = ^TNoCollection;
TNoCollection = object(TCollection)
ItemSize: word;
constructor Init(ALimit, ADelta: Integer; Size: Word);
procedure FreeItem(Item: Pointer); virtual;
function GetItem(var S: TStream): pointer; virtual;
procedure PutItem(var S: TStream; Item: Pointer); virtual;
end;
const
RStrObj : TStreamRec = (
ObjType: $FFFF;
VmtLink: Ofs(TypeOf(TStrObj)^);
Load: @TStrObj.Load;
Store: @TStrObj.Store
);
implementation
uses App, MsgBox;
function StrFn(A: Longint): string;
var s: string;
begin
Str(A,S);
StrFn := s;
end;
procedure Error(var s: tStream); far;
var w: word;
begin
if StatusLine = Nil then
begin
writeln('Stream failure. Status = ',s.Status,'. Info = ',s.ErrorInfo,'.');
halt(1);
end;
w := MessageBox('Stream process failed with a Code of '
+StrFn(s.Status)+' and an Info of '+StrFn(s.ErrorInfo),nil,mfError+mfOKButton);
s.Reset;
end;
constructor tstrobj.Init;
begin
p := NewStr(S);
end;
constructor tStrObj.Load;
begin
P := S.ReadStr;
end;
procedure tStrObj.Store;
begin
S.WriteStr(P);
end;
destructor tstrobj.Done;
begin
disposeStr(p);
tObject.done;
end;
function TStrObj.GetString: String;
begin
If p = nil then GetString := '' else
GetString := P^;
end;
constructor TNOCollection.Init;
begin
TCollection.Init(Alimit, Adelta);
ItemSize := Size;
end;
procedure TNOCollection.FreeItem;
begin
Dispose(Item);
end;
function TNOCollection.GetItem(var S:TStream): pointer;
var P: pointer;
begin
GetMem(p,ItemSize);
S.Read(P^,ItemSize);
GetItem := P;
end;
procedure TNOCollection.PutItem(var S:TStream; Item: Pointer);
begin
S.Write(Item^,ItemSize);
end;
function TStrObjCollection.StringAt(I: Integer): string;
begin
StringAt := PStrObj(At(I))^.GetString;
end;
function TStrCollection.Compare(Key1, Key2: Pointer): Integer;
begin
Compare := 1;
end;
begin
Objects.StreamError := @Error;
end.